const { Controller } = require('egg')

const errorMessageMap = {
  201: '账号未登录',
  202: '账号或密码错误',
  203: '操作失败'
}

class BaseController extends Controller {
  resSuccess(data, message = '成功') {
    const ctx = this.ctx
    ctx.body = {
      code: 200,
      message,
      data
    }
  }

  resError(code = 201) {
    const ctx = this.ctx
    console.log(errorMessageMap[code]);
    ctx.body = {
      code,
      message: errorMessageMap[code]
    }
  }
}

module.exports = BaseController